/*
 * TelaGerenciamento.java
 *
 * Created on 4 de Setembro de 2008, 19:34
 */
package gui;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import logica.MemoriaFisica;
import logica.MemoriaLogica;

import logica.Random;
import logica.TabelaPaginas;
import logica.UGM;

/**
 *
 * @author  Thiago A. L. Genez
 */
public class TelaGerenciamento extends javax.swing.JFrame {

    private String nomeProcesso = null;
    private Integer qtdPagina = null;
    private Integer qtdFrame = null;
    private Integer tamanhoProcesso = null;
    private String tamanhoPaginaFrame = null;
    private TabelaPaginas tabelaPaginas = null; // @jve:decl-index=0:

    private Boolean passoApasso = null;
    private MemoriaFisica memoriaFisica = null;
    private MemoriaLogica memoriaLogica = null;
    private DefaultTableCellRenderer centralizado = null;
    private Vector<String> pagProcesso = null;
    private List<String> filaRAM = null;
    private JButton ghost = null;

    /** Creates new form TelaGerenciamento */
    public TelaGerenciamento(String nomeProcesso, Integer qtdPagina,
            Integer qtdFrame, Integer tamanhoProcesso, String tamanho) {
        this.tabelaPaginas = new TabelaPaginas(qtdPagina);
        this.memoriaFisica = new MemoriaFisica(qtdFrame, new Integer(qtdFrame * Integer.parseInt(tamanho.substring(0, tamanho.length() - 1)) * 1024));
        this.memoriaLogica = new MemoriaLogica(qtdPagina, new Integer(qtdFrame * Integer.parseInt(tamanho.substring(0, tamanho.length() - 1)) * 1024));
        this.nomeProcesso = nomeProcesso;
        this.qtdFrame = qtdFrame;
        this.qtdPagina = qtdPagina;
        this.tamanhoProcesso = tamanhoProcesso;
        this.tamanhoPaginaFrame = tamanho;
        this.centralizado = new DefaultTableCellRenderer();
        this.centralizado.setHorizontalAlignment(SwingConstants.CENTER);
        this.filaRAM = new ArrayList<String>(qtdFrame);
        this.passoApasso = new Boolean(true);
        this.setarGhost();
        initComponents();
        this.startButton.setEnabled(true);
        this.stepByStepButton.setEnabled(true);
        this.pintarTabelaProcessos(tamanhoProcesso);
        this.pintarTabelaVirtual(tamanhoProcesso);
        this.setVisible(true);
        this.setResizable(false);
        this.setLocationRelativeTo(null);


    }

    private void pintarTabelaProcessos(Integer numeroPaginaProcesso) {
        this.pagProcesso = new Stack<String>();
        for (int i = 0; i < numeroPaginaProcesso.intValue(); i++) {
            jTable3.setValueAt(new String("ConjuntoIntrucao" + String.valueOf(i)), 9 - i, 1);
            this.pagProcesso.addElement(new String("ConjuntoIntrucao" + String.valueOf(i)));
        }
    }

    private void pintarTabelaVirtual(Integer numeroPaginaProcesso) {
        for (int i = 0; i < numeroPaginaProcesso.intValue(); i++) {


            Integer posicao = Random.gerarRandom(0, 16 * 4096 - 1);
            if (ramTable.getValueAt(UGM.getUGM(posicao), 1) != null) {
                i--;
            } else {
                ramTable.setValueAt(this.pagProcesso.get(i), UGM.getUGM(posicao), 1);
                ramTable.setValueAt(false, UGM.getUGM(posicao), 3);
            }

        }
    }

    private class ThreadStart extends Thread {

        @Override
        public void run() {
            while (true) {
                synchronized (this) {
                    try {
                        Thread.sleep(20);
                        ghost.doClick();
                    } catch (InterruptedException ex) {
                        Logger.getLogger(TelaGerenciamento.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    }

    private synchronized void iniciarGerenciamento() {

        if (filaRAM.size() < 5) {
            Integer posicao = Random.gerarRandom(0, 16 * 4096 - 1);
            if (ramTable.getValueAt(UGM.getUGM(posicao), 3) != null) {
                if (!(Boolean) ramTable.getValueAt(UGM.getUGM(posicao), 3)) {
                    Integer posicaoRam = Random.gerarRandom(0, 5 * 4096 - 1);
                    while (jTable1.getValueAt(4 - UGM.getUGM(posicaoRam), 1) == null) {
                        ramTable.setValueAt(true, UGM.getUGM(posicao), 3);
                        String intrucao = (String) ramTable.getValueAt(UGM.getUGM(posicao), 1);
                        filaRAM.add(pagProcesso.get(Integer.parseInt(intrucao.substring(16))));
                        jTable1.setValueAt(pagProcesso.get(Integer.parseInt(intrucao.substring(16))), 4 - UGM.getUGM(posicaoRam), 1);
                        jTable2.setValueAt(UGM.getUGM(posicaoRam), UGM.getUGM(posicao), 1);
                    }
                }
            }
        } else {
            String removido = (String) filaRAM.remove(0);
            int quadroDaPaginaRemovida = 0;
            for (int i = 0; i < 5; i++) {
                String procurado = (String) jTable1.getValueAt(i, 1);
                if (procurado.equals(removido)) {
                    jTable1.setValueAt(null, i, 1);
                    quadroDaPaginaRemovida = 4 - i;
                    break;
                }
            }

            for (int i = 0; i < 16; i++) {
                Integer paginaProcurada = (Integer) jTable2.getValueAt(i, 1);
                if (paginaProcurada != null) {
                    if (quadroDaPaginaRemovida == paginaProcurada.intValue()) {
                        jTable2.setValueAt(null, i, 1);
                        ramTable.setValueAt(false, i, 3);
                        break;
                    }
                }
            }
        }

    }

    private void setarGhost() {
        if (ghost == null) {
            ghost = new JButton();
            ghost.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent e) {
                    iniciarGerenciamento();
                }
            });
        }
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        simuladorPanel = new javax.swing.JPanel();
        memVirtualPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        ramTable = new javax.swing.JTable();
        memRamPanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        sairButton = new javax.swing.JButton();
        startButton = new javax.swing.JButton();
        stepByStepButton = new javax.swing.JButton();
        stopButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Simulador S.O. - Gerenciador de Memoria");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        simuladorPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Simulador", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        memVirtualPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Memoria Virtual"));

        ramTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {new Integer(15), null, "60k - 64k", null},
                {new Integer(14), null, "56k - 60k", null},
                {new Integer(13), null, "52k - 56k", null},
                {new Integer(12), null, "48k - 52k", null},
                {new Integer(11), null, "44k - 48k", null},
                {new Integer(10), null, "40k - 44k", null},
                {new Integer(9), null, "36k - 40k", null},
                {new Integer(8), null, "32k - 36k", null},
                {new Integer(7), null, "28k - 32k", null},
                {new Integer(6), null, "24k - 28k", null},
                {new Integer(5), null, "20k - 24k", null},
                {new Integer(4), null, "16k - 20k", null},
                {new Integer(3), null, "12k - 16k", null},
                {new Integer(2), null, "8k - 12k", null},
                {new Integer(1), null, "4k - 8k", null},
                {new Integer(0), null, "0k - 4k", null}
            },
            new String [] {
                "Id Pagina", "Pagina Processo", "Enderecamento", "Bit Presenca"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(ramTable);
        ramTable.getColumnModel().getColumn(0).setPreferredWidth(40);
        ramTable.getColumnModel().getColumn(1).setPreferredWidth(120);
        ramTable.getColumnModel().getColumn(2).setPreferredWidth(100);
        ramTable.getColumnModel().getColumn(0).setResizable(false);
        ramTable.getColumnModel().getColumn(1).setResizable(false);
        ramTable.getColumnModel().getColumn(2).setResizable(false);
        ramTable.getColumnModel().getColumn(3).setResizable(false);
        ramTable.getColumnModel().getColumn(0).setCellRenderer(centralizado);
        ramTable.getColumnModel().getColumn(1).setCellRenderer(centralizado);
        ramTable.getColumnModel().getColumn(2).setCellRenderer(centralizado);
        ramTable.getColumnModel().getColumn(3).setCellRenderer(centralizado);

        javax.swing.GroupLayout memVirtualPanelLayout = new javax.swing.GroupLayout(memVirtualPanel);
        memVirtualPanel.setLayout(memVirtualPanelLayout);
        memVirtualPanelLayout.setHorizontalGroup(
            memVirtualPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
        );
        memVirtualPanelLayout.setVerticalGroup(
            memVirtualPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(memVirtualPanelLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
                .addContainerGap())
        );

        memRamPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Memoria RAM"));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {new Integer(4), null, "16k - 20k"},
                {new Integer(3), null, "12k - 16k"},
                {new Integer(2), null, "8k - 12k"},
                {new Integer(1), null, "4k - 8k"},
                {new Integer(0), null, "0k - 4k"}
            },
            new String [] {
                "ID Quadro", "Pagina", "Endereçamento"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setResizable(false);
        jTable1.getColumnModel().getColumn(1).setResizable(false);
        jTable1.getColumnModel().getColumn(2).setResizable(false);
        jTable1.getColumnModel().getColumn(0).setCellRenderer(centralizado);
        jTable1.getColumnModel().getColumn(1).setCellRenderer(centralizado);
        jTable1.getColumnModel().getColumn(2).setCellRenderer(centralizado);

        javax.swing.GroupLayout memRamPanelLayout = new javax.swing.GroupLayout(memRamPanel);
        memRamPanel.setLayout(memRamPanelLayout);
        memRamPanelLayout.setHorizontalGroup(
            memRamPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
        );
        memRamPanelLayout.setVerticalGroup(
            memRamPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(memRamPanelLayout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Tabela Páginas"));

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {new Integer(15), null},
                {new Integer(14), null},
                {new Integer(13), null},
                {new Integer(12), null},
                {new Integer(11), null},
                {new Integer(10), null},
                {new Integer(9), null},
                {new Integer(8), null},
                {new Integer(7), null},
                {new Integer(6), null},
                {new Integer(5), null},
                {new Integer(4), null},
                {new Integer(3), null},
                {new Integer(2), null},
                {new Integer(1), null},
                {new Integer(0), null}
            },
            new String [] {
                "Pag. Lógica", "Pag. Física"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(jTable2);
        jTable2.getColumnModel().getColumn(0).setResizable(false);
        jTable2.getColumnModel().getColumn(1).setResizable(false);
        jTable2.getColumnModel().getColumn(0).setCellRenderer(centralizado);
        jTable2.getColumnModel().getColumn(1).setCellRenderer(centralizado);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Processo"));

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {new Integer(9), null},
                {new Integer(8), null},
                {new Integer(7), null},
                {new Integer(6), null},
                {new Integer(5), null},
                {new Integer(4), null},
                {new Integer(3), null},
                {new Integer(2), null},
                {new Integer(1), null},
                {new Integer(0), null}
            },
            new String [] {
                "ID - Pagina", "Conjunto Intrucoes"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane4.setViewportView(jTable3);
        jTable3.getColumnModel().getColumn(0).setPreferredWidth(10);
        jTable3.getColumnModel().getColumn(0).setResizable(false);
        jTable3.getColumnModel().getColumn(1).setResizable(false);
        jTable3.getColumnModel().getColumn(0).setCellRenderer(centralizado);
        jTable3.getColumnModel().getColumn(1).setCellRenderer(centralizado);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
        );

        sairButton.setText("Exit");
        sairButton.setToolTipText("Sair da Aplicacao");
        sairButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairButtonActionPerformed(evt);
            }
        });

        startButton.setText("Start");
        startButton.setToolTipText("Iniciar a Thread, Gerenciamento Automatico");
        startButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startButtonActionPerformed(evt);
            }
        });

        stepByStepButton.setText("Step by Step");
        stepByStepButton.setToolTipText("Gerenciamento Passo-a-Passo");
        stepByStepButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stepByStepButtonActionPerformed(evt);
            }
        });

        stopButton.setText("Reiniciar");
        stopButton.setToolTipText("Restart na Aplicacao");
        stopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout simuladorPanelLayout = new javax.swing.GroupLayout(simuladorPanel);
        simuladorPanel.setLayout(simuladorPanelLayout);
        simuladorPanelLayout.setHorizontalGroup(
            simuladorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(simuladorPanelLayout.createSequentialGroup()
                .addGroup(simuladorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(memVirtualPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, simuladorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(memRamPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, simuladorPanelLayout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(simuladorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(stepByStepButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(startButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                            .addGroup(simuladorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(stopButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(sairButton, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(simuladorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(simuladorPanelLayout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );
        simuladorPanelLayout.setVerticalGroup(
            simuladorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(simuladorPanelLayout.createSequentialGroup()
                .addGroup(simuladorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, 0, 320, Short.MAX_VALUE)
                    .addComponent(memVirtualPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(simuladorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(simuladorPanelLayout.createSequentialGroup()
                        .addComponent(memRamPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(simuladorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sairButton)
                            .addComponent(startButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(simuladorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(stopButton)
                            .addComponent(stepByStepButton)))
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(simuladorPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(simuladorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void sairButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairButtonActionPerformed
        System.exit(0);
    }//GEN-LAST:event_sairButtonActionPerformed

    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed
        this.stepByStepButton.setEnabled(false);
        new ThreadStart().start();
        this.startButton.setEnabled(false);
    }//GEN-LAST:event_startButtonActionPerformed

    private void stepByStepButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stepByStepButtonActionPerformed
        this.startButton.setEnabled(false);
        if (this.passoApasso.booleanValue()) {
            this.passoApasso = false;
            JOptionPane.showMessageDialog(null, "Observação: Quando clicado no botao \"Step by Step\" e nada acontecer,\nocoreu a seguinte situcao:\n\n1- Foi escolhido uma página da memoria Virtual, que nao tem nehum conjunto de instrucao alocado!!\n2- A pagina escolhida já se encontra na memoria RAM\n\n\nOBS: essa mensagem nao ira aparecer nas proximas vezes", "Atenção", JOptionPane.WARNING_MESSAGE);
        }
        this.iniciarGerenciamento();
    }//GEN-LAST:event_stepByStepButtonActionPerformed

private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed
    new TelaGerenciamento(this.nomeProcesso,
            (Integer) this.qtdPagina,
            (Integer) this.qtdFrame,
            (Integer) this.tamanhoProcesso,
            (String) this.tamanhoPaginaFrame);
    TelaGerenciamento.this.dispose();
}//GEN-LAST:event_stopButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JPanel memRamPanel;
    private javax.swing.JPanel memVirtualPanel;
    private javax.swing.JTable ramTable;
    private javax.swing.JButton sairButton;
    private javax.swing.JPanel simuladorPanel;
    private javax.swing.JButton startButton;
    private javax.swing.JButton stepByStepButton;
    private javax.swing.JButton stopButton;
    // End of variables declaration//GEN-END:variables
}
